home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
unix
/
c
/
open
< prev
next >
Wrap
Text File
|
1996-11-09
|
2KB
|
105 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/open,v $
* $Date: 1996/10/30 21:59:01 $
* $Revision: 1.2 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: open,v $
* Revision 1.2 1996/10/30 21:59:01 unixlib
* Massive changes made by Nick Burret and Peter Burwood.
*
* Revision 1.1 1996/04/19 21:35:27 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: open,v 1.2 1996/10/30 21:59:01 unixlib Rel $";
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/syslib.h>
#include <sys/unix.h>
#include <sys/dev.h>
#include <sys/types.h>
struct sfile __sfile[] =
{
{"tty", makedev (DEV_TTY, 0)},
{"console", makedev (DEV_TTY, 0)},
{"rs423", makedev (DEV_TTY, 0)},
{"null", makedev (DEV_NULL, 0)},
{0, makedev (DEV_RISCOS, 0)}}; /* table terminator */
char *
ttyname (int fd)
{
fd = fd;
return ("/dev/tty");
}
int
open (const char *file, int oflag, ...)
{
register struct file *f;
va_list ap;
register int mode;
int fd;
dev_t dev;
/* __uname() is called by __fsopen() */
if (oflag & O_CREAT)
{
va_start (ap, oflag);
mode = va_arg (ap, int);
va_end (ap);
}
else
mode = 0777;
if ((fd = __fdalloc ()) < 0)
return (-1);
f = __u->file + fd;
f->oflag = oflag;
if (file[0] == '/' && file[1] == 'd' && file[2] == 'e' &&
file[3] == 'v' && file[4] == '/')
{
register struct sfile *s = __sfile;
register char *s1, *s2;
while (s1 = s->name)
{
s2 = (char *)file + 5;
while (*s1 && *s2 && *s1 == *s2)
s1++, s2++;
if (*s1 == *s2)
break;
s++;
}
dev = s->dev;
}
else
dev = makedev (DEV_RISCOS, 0);
{
register int i;
if ((i = __funcall ((*(__dev[major (dev)].open)), ((char *)file, mode, f))) < 0)
return (-1);
f->dev = makedev (major (dev), i);
}
f->dup = f;
f->pid = __u->pid;
return (fd);
}